<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- <button @click="handleChange">改变info</button> -->
        <button @click="handleChangeInfoName">改变info的名字</button>
    </div>
    <script src="../../js/vue.js"></script>
    <script>
        const dcl = {
            data() {
                return {
                    info: {
                        name: 'Steve Jobs',
                        age: 18,
                        nba: {
                            name: 'kobe'
                        }
                    }
                }
            },
            watch: {
                // info(newValue, oldValue) {
                //     console.log('newValue:', newValue, 'oldValue:', oldValue)
                // },
                info: {
                    handler: function (newInfo, oldInfo) {
                        console.log('newValue:', newInfo, 'oldValue:', oldInfo)
                    },
                    deep: true, // 深度监听
                    immediate: true
                }
            },
            methods: {
                handleChange() {
                    this.info = {
                        name: 'Jack'
                    }
                },
                handleChangeInfoName(){
                    this.info.nba.name = 'james1';
                }
            }
        }
        Vue.createApp(dcl).mount('#app');
    </script>
</body>

</html>